package com.yanqu.road.server.cmd.cookboy;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.activity.eActivityCookBoyType;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyActivityMgr;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_COOK_BOY_WORSHIP, desc = "膜拜排行第一名")
public class CookBoyWorshipCmd extends AbstractCommand {

	int activityId;
	String reward;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CookBoyProto.CookBoyWorshipReqMsg reqMsg = CookBoyProto.CookBoyWorshipReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo activityInfo = CookBoyActivityMgr.getOpenActivityInfo(activityId);
		if(activityInfo == null){
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
			return;
		}
		if(activityInfo.getChildType() == eActivityCookBoyType.Process1.getChildType()){
			ret = CookBoyMgr.worship(activityId,player.getUserId());
		}else if(activityInfo.getChildType() == eActivityCookBoyType.Process2.getChildType()){
			ret = CookBoyMgr.worship2(activityId,player.getUserId());
		}else if(activityInfo.getChildType() == eActivityCookBoyType.Process3.getChildType()){
			ret = CookBoyMgr.worship3(activityId,player.getUserId());
		}else{
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
		}

	}

	@Override
	public void sendData(GamePlayer player) {
		CookBoyProto.CookBoyWorshipRespMsg.Builder respMsg = CookBoyProto.CookBoyWorshipRespMsg.newBuilder();
		respMsg.setRet(ret);
		if(ret == 0){
			ActivityInfo activityInfo = CookBoyActivityMgr.getOpenActivityInfo(activityId);
			if(activityInfo.getChildType() == eActivityCookBoyType.Process1.getChildType()){
				respMsg.setReward(CookBoyActivityMgr.getWorshipReward(activityId));
			}else if(activityInfo.getChildType() == eActivityCookBoyType.Process2.getChildType()){
				respMsg.setReward(CookBoyActivityMgr.getWorship2Reward(activityId));
			}else if(activityInfo.getChildType() == eActivityCookBoyType.Process3.getChildType()){
				respMsg.setReward(CookBoyActivityMgr.getWorship3Reward(activityId));
			}
		}
		player.sendPacket(Protocol.U_COOK_BOY_WORSHIP, respMsg);
	}
}
